$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'account/manage/seq/list?accountType=jing_bao',
        datatype: "json",
        colModel: [
            { label: '主键', name: 'id', index: "id", width: 110, hidden:true, key: true },
            { label: '用户姓名', name: 'realName', width: 45 },
            { label: '手机号', name: 'mobileNumber', width: 90 },
            { label: '变动类型', name: 'changeTypeName', width: 75 },
            { label: '来账/往账', name: 'seqFlagName', width: 75 },
            { label: '变动前金额', name: 'preAmount', width: 75 },
            { label: '变动金额', name: 'changeAmount', width: 75 },
            { label: '变动后金额', name: 'amount', sortable: false, width: 75 },
            { label: '生成时间', name: 'createTime', index: "create_time", width: 85}
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: false,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.result",
            page: "page.pageNo",
            total: "page.totalPages",
            records: "page.total"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});


var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            realName: null,
            mobileNumber:null
        },
        showList: true,
        infoList: false,
        title:null,
        userDetalTitle:null,
        accouts:[],
        user:{
            status:1
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        info: function(){
            var grid = $("#jqGrid");
            var userId = grid.getGridParam("selrow");
            if(!userId){
                alert("请选择一条记录");
                return ;
            }

            vm.showList = false;
            vm.infoList = true;
            vm.userDetalTitle = "用户详情";

            vm.getUser(userId);
        },
        getUser: function(userId){
            $.get(baseURL + "users/user/info/"+userId, function(r){

                vm.user = r.user;
                vm.accouts = r.accouts;
                vm.user.password = null;

            });
        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{'realName': vm.q.realName,'mobileNumber': vm.q.mobileNumber},
                page:page
            }).trigger("reloadGrid");
        },
        infoReload: function () {
            vm.showList = true;
            vm.infoList = false;
        },
        accoutDetail:function (userId,accountTypeCode) {
            localStorage.setItem('userId', userId);
            localStorage.setItem('accountTypeCode', accountTypeCode);

            layer.open({
                type: 2,
                skin: 'layui-layer-molv',
                title: "变动记录",
                shadeClose: false,
                area: ['700px', '450px'],
                fixed: false, //不固定
                maxmin: true,
                content: '../users/userAccout.html'
            });
        }
    }
});